package SpringEvent;

import SpringEvent.event.MyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * https://www.it610.com/article/1282423505006116864.htm
 * @author caihe
 * @date 2021/11/10 15:57
 */
@SpringBootApplication
@RestController
public class SpringEventApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringEventApplication.class, args);
    }

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @GetMapping("/event")
    public String event() {
        MyEvent myEvent = new MyEvent(this);
        applicationEventPublisher.publishEvent(myEvent);
        return "ok";
    }

    @GetMapping("/annotateEvent")
    public String annotateEvent() {
        AnnotateEvent annotateEvent = new AnnotateEvent(this);
        applicationEventPublisher.publishEvent(annotateEvent);
        return "annotateEvent";
    }
}
